import request from '@/utlis/request'
import type { CategoryResponseData, AttrResponseData, Attr } from './type'
enum API {
  // 一级分类
  CATEGORY1_URL = '/admin/product/getCategory1',
  //二级分类
  CATEGORY2_URL = '/admin/product/getCategory2/',
  //三级分类
  CATEGORY3_URL = '/admin/product/getCategory3/',
  // 获取分类下已有的属性值
  ATTR_URL = '/admin/product/attrInfoList/',
  // 添加或修改已有的属性接口
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  // 删除某一个已有的属性
  DELECTATTR_URL = '/admin/product/deleteAttr/',
}

// 获取一级分类
export const reqCategory1 = () =>
  request.get<any, CategoryResponseData>(API.CATEGORY1_URL)

// 获取二级分类
export const reqCategory2 = (category1Id: number | string) =>
  request.get<any, CategoryResponseData>(API.CATEGORY2_URL + category1Id)

// 获取三级分类
export const reqCategory3 = (category2Id: number) =>
  request.get<any, CategoryResponseData>(API.CATEGORY3_URL + category2Id)

//获取对应分类下的商品的详情
export const reqAttr = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, AttrResponseData>(
    API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )

// 新增或修改已有的属性接口
export const reqAddOrUpdateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATEATTR_URL, data)

// 删除某一个已有属性

export const reqRemoveAttr = (attrId: number) =>
  request.delete<any, any>(API.DELECTATTR_URL + attrId)
